//import 'dart:convert';
//import 'dart:io';
//
//import 'package:crypto/crypto.dart';
//import 'package:dio/dio.dart';
//import 'package:hf_flutter/base_lib/config/BuildConfig.dart';
//
//class OSSUpload {
////验证文本域
//  static String policyText =
//      '{"expiration": "2025-01-01T12:00:00.000Z","conditions": [{"bucket": "${BuildConfig.OSS_NAME}" },["content-length-range", 0, 1048576000]]}';
//
////进行utf8编码
//  static List<int> policyText_utf8 = utf8.encode(policyText);
//
////进行base64编码
//  static String policy_base64 = base64.encode(policyText_utf8);
//
////再次进行utf8编码
//  static List<int> policy = utf8.encode(policy_base64);
//
//  static String accesskey = BuildConfig.OSS_ACCESS_KEY;
//
////进行utf8 编码
//  static List<int> key = utf8.encode(accesskey);
//
////通过hmac,使用sha1进行加密
//  static List<int> signature_pre = new Hmac(sha1, key).convert(policy).bytes;
//
//  //最后一步，将上述所得进行base64 编码
//  static String signature = base64.encode(signature_pre);
//
//  static Future<String> uploadHeadFile(String path) async {
//    return uploadIDHeadFile(path, "");
//  }
//
//  static Future<String> uploadIDHeadFile(String path, String id) async {
//    return uploadFile("userId_$id/imghead", path);
//  }
//
//  static Future<String> uploadNormalFile(String path) async {
//    return uploadFile("img",path);
//  }
//
//  static Future<String> uploadFile(String key, String path) async {
//    //dio的请求配置，这一步非常重要！
//    Options options = new Options();
//    options.responseType = ResponseType.plain;
//
//    //创建dio对象
//    Dio dio = new Dio();
//    //文件名
//    String fileName = md5
//            .convert(
//                utf8.encode("${DateTime.now().millisecondsSinceEpoch}$path"))
//            .toString() +
//        "";
//    List<String> suffixList = path.split(".");
//    String suffix = suffixList.last == null ? "": "."+suffixList.last;
//
//    //创建一个formdata，作为dio的参数
//    FormData data = new FormData.fromMap({
//      'key': "$key/$fileName" + suffix,
//      'policy': policy_base64,
//      'OSSAccessKeyId': BuildConfig.OSS_KEY_ID,
//      'success_action_status': '200', //让服务端返回200，不然，默认会返回204
//      'signature': signature,
//      'file': await MultipartFile.fromFile(path,filename: fileName)
//    });
//
//    try {
//      await dio.post(
//          "https://${BuildConfig.OSS_NAME}.oss-cn-hangzhou.aliyuncs.com",
//          data: data,
//          options: options);
//      return _presignPublicURL("$key/$fileName$suffix");
//    } on DioError catch (e) {
//      print(e.message);
//    }
//    return "";
//  }
//
//  static String _presignPublicURL(String fileStr) {
//    return "https://${BuildConfig.OSS_NAME}.oss-cn-hangzhou.aliyuncs.com/${Uri.encodeComponent(fileStr.trim()).replaceAll("+", "%20").replaceAll("*", "%2A").replaceAll("%7E", "~").replaceAll("%2F", "/")}";
//  }
//}
